<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遍历来自数据库的结果</title>
</head>

<body>
    <h1>通过服务器上的 PHP 文件获取 JSON 数据</h1>
    <p id="demo"></p>
    <script>
        var xmlhttp, myObj, x, txt = "";
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
                myObj = JSON.parse(this.responseText);
                for (x in myObj) {
                    txt += myObj[x].CustomerId + "<br>";
                }
                document.getElementById("demo").innerHTML = txt;
            }
        };
        xmlhttp.open("GET", "/demo/demo_json_db.php", true);
        xmlhttp.send();
    </script>
</body>

</html>